<?php

class admin_Form_Admin extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );	

    public function cluBuild($params)
    {
        // set the method for the display form to POST
        $this->setMethod('GET');
        
        $this->setAction($params['action_url']);
		
        //themes
        $themes = new Zend_Form_Element_Select('themes', 
                         	array('disableLoadDefaultDecorators' => true,));
        $t = Zend_Registry::get('configuration')->general->defaultTheme;
		$themes->addMultiOption($t,$t);
		$themes->addDecorators($this->_noDecorator);
        $this->addElement($themes);                      
                         
        //add choose_module
        $choose_module = new Zend_Form_Element_Select('content_module', 
                         array('disableLoadDefaultDecorators' => true,
                               'required'   => true
								));
        foreach (explode(' ', Zend_Registry::get('configuration')->moduleList) as $t)
            $choose_module->addMultiOption($t, $t);
        $choose_module->addDecorators($this->_noDecorator);
        $this->addElement($choose_module);
        
        //add type
        $type = new Zend_Form_Element_Select('type', 
                         array('disableLoadDefaultDecorators' => true,
								));
		foreach (explode(' ', Zend_Registry::get('configuration')->nodeTypes) as $t)
        	$type->addMultiOption($t, $t);
        $type->addDecorators($this->_noDecorator);
        $this->addElement($type);
		
		//request
		$request = new Zend_Form_Element_Select('request', 
                         	array('disableLoadDefaultDecorators' => true,));
		$request->addMultiOption(0,t(97))
       			->addDecorators($this->_noDecorator);
        $this->addElement($request);  
        
        //widget_name
		$widget_position_id = new Zend_Form_Element_Select('widget_position_id', 
                         	array('disableLoadDefaultDecorators' => true,));
		$widget_position_id->addMultiOption(0,t(97))
       			->addDecorators($this->_noDecorator);
        $this->addElement($widget_position_id);  
        
        // add the submit button
        $submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => t(627)));
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);
    }
    
    public function populateFormData($data)
    {
    	if (isset($data['content_module']))
	    {
	    	$data['site'] = 'hvn';
	    	$mWeight = new admin_Model_Weight();
	    	$dataWidgetPosition = $mWeight->getDataWidgetPosition($data);
			foreach ($dataWidgetPosition as $d) {
          	    $this->request->addMultiOption($d['id'], $d['master_request']);
     		}
        }
        if (isset($data['request']))
	    {
	    	$mWeight = new admin_Model_Weight();
	    	$dataWidgetName = $mWeight->getWidgetName($data['request']);
			foreach ($dataWidgetName as $n) {
          	    $this->request->addMultiOption($n['widget_name'], $n['widget_name']);
     		}
        }
    	$this->populate($data);
    }
} 
?>
